home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / animutil / kfast / kfast.txt < prev    next >
Text File  |  1992-07-03  |  8KB  |  169 lines

  1. KFAST - Key Frame Animator with Skeletal Technique
  2.  
  3. KFAST is a collection of functions to implement a two-dimensional
  4. object based animator designed to use the skeletal technique of
  5. modeling objects and simple tweening to free the animator from the
  6. labors of producing smooth transitions between key drawings.
  7. A crude demo program has been included utilizing the routines.
  8.    
  9. *** The req.library is required for the demo program ***
  10.  
  11. Public Domain, Source in C included.
  12. Author:  Craig M. Lever
  13.  
  14. DISCLAIMER
  15.    I make no warrantee to the usefulness of this program nor can I
  16.    be held responsible for any damage caused while using it.
  17.    I release this program and source into the public domain.   
  18.  
  19. REACHING ME
  20.    While I'm releasing the source as PD I'm still interested in hearing
  21.    if anyone puts the source to good use.
  22.  
  23.    I can be reached at the following mailing address:
  24.         Craig Lever
  25.         RR #1.
  26.         Airdrie, Alberta, Canada.
  27.         T4B 2A3
  28.  
  29.    I can also be reached through some of the Fido Amiga echoes
  30.    or by Fido Netmail at:
  31.         Craig Lever @ 1:134/27.0 - The AMUC Express
  32.    or by UseNet Netmail at:
  33.         cmlever@wwshop.cuc.ab.ca - The Wizard's Workshop
  34.  
  35. THE PROGRAM
  36.    The animator is a test bed I used to make sure the functions
  37.    for the inbetweening work correctly.  For this reason a number of
  38.    features have not been included.  If someone wishes to fill in the
  39.    gaps feel free.  The underlying routines which calculate
  40.    inbetweened objects are fairly complete (support for transparant
  41.    colors was never added) but some eager programmer could overhaul
  42.    them to reduce temporary memory consumption.  If someone does
  43.    undertake the task, here's my wish list for the interface :-):
  44.         color palette and screen resolution control
  45.         nice editing functions and the ability to enter     
  46.           independant objects
  47.         precreated objects like circles, rectangles and fonts
  48.           since freehand is frustrating
  49.  
  50.    To try the program out start it (either from the WB or CLI) and
  51.    a list of commands will be displayed.  After skimming these 
  52.    (they can be redisplayed by hitting "h") select the "OK" gadget.
  53.    Now hit "r" which will bring up a requester to read in a file and
  54.    select the file "Example.kfast".  Using the "n" and "p" key you
  55.    can move through the frames and see just what the input file
  56.    included.  Then hit "a" and it will generate images for the
  57.    remaining frames (a slow process which may require 300K).
  58.    Once that is done you should be able to scroll through the frames
  59.    with the space bar.  No I'm NOT and artist I realize that but
  60.    it shows how the routines respond given the amount of information
  61.    (an image and/or a skeleton and outline) in the surrounding key
  62.    frames.
  63.      
  64. THEORY OF KEY FRAME ANIMATION
  65.    Inbetweening, or tweening, is the process by which the computer
  66.    calculates the additional drawings between specified "key" frames
  67.    by computing linear distances between corresponding points in each
  68.    of the keys.  For a given velocity law between the key frames the
  69.    intermediate locations can be calculated and the object can be
  70.    reconstructed for those intermediate frames.
  71.  
  72.    For tweening, the simplest case is to assume the objects in the key
  73.    frames are composed of strokes which are composed of line segments
  74.    joined end-to-end.  Since it is unlikely that the object in the
  75.    each key frames has the exact same number of strokes composed of
  76.    the exact same number of line segments some preprocessing is
  77.    required.  One method, is to simply subdivide strokes and/or line
  78.    segments until each key has the same number.
  79.  
  80.    This is accomplished by the following algorithm:
  81.         1. Preprocessing for a different number of strokes
  82.              Let 01 and 02 represent the corresponding key objects
  83.              Let N1 and N2 equal the # of strokes in O1 and O2
  84.              respectively.
  85.              if(N1>N2) then the following values are computed:
  86.                RT = N1 div N2
  87.                RS = N1 mod N2
  88.              then RS strokes of O2 are broken up into RT+1 strokes and
  89.              the remaining strokes are broken into RT strokes.
  90.  
  91.         2. Preprocessing for different number of point for
  92.            corresponding strokes
  93.              Let S1 and S2 represent the corresponding strokes
  94.              Let NP1 and NP2 equal the # of points in S1 and S2
  95.              respectively.
  96.              if(NP1>NP2) then the following values are computed:
  97.                RT = (NP1-1) div (NP2-1)
  98.                RS = (NP1-1) mod (NP2-1)
  99.              then RT points are added to the first RS line segments of
  100.              S2 and RT-1 are added to the remaining line segments.
  101.  
  102.    To visualize this draw two frames. The first with two strokes: the
  103.    first composed of 6 points (label them a b c d e & f) joined by
  104.    line segments and the second stroke composed of three points(label
  105.    these 1 2 & 3).  The second frame is a single stroke of 8 points
  106.    (label these A B C D E F G H).
  107.    Note if you want closed objects the first and last points must be
  108.    the same and count as 2 points.
  109.  
  110.    For stroke preprocessing RT is determined to be 2 and RT is 0.
  111.    Therefore zero strokes are broken into 3 strokes and the remaining
  112.    strokes are broken into two strokes.  So stroke ABCDEFGH becomes
  113.    two strokes ABCD and DEFGH.  (The break point is logically chosen
  114.    at the halfway point D and both resulting segments contain point D)
  115.  
  116.    Looking at the second pair of strokes, 123 and DEFGH, the point
  117.    preprocessing again gives RT=2 and RS=0.
  118.    Therefore zero segments of object 1 are divided into 3 line
  119.    segments and all remaining segments are divided in two.
  120.    This gives the stroke 11'22'3 where 1' is choosen halfway between 1
  121.    and 2 and similarly 2' is halfway between 2 and 3.
  122.  
  123.    Once this is done a velocity law must be chosen to determine where
  124.    each point in the object is position for the inbetweens.  There are
  125.    four general cases which can be applied in any combination as the
  126.    velocity law for x and y relative motion:
  127.      1) Velocity constant
  128.      2) Velocity accelerating
  129.      3) Velocity decelerating
  130.      4) Velocity accelerating then decelerating
  131.  
  132.    These four cases allow the animation to be fine tuned so as not to
  133.    appear too "jerky".  A rough example of these can be made by
  134.    showing how the distance moved changes if an object was crossing
  135.    the screen.  The numbers represent the frame number.
  136.  
  137.                  Start                                      End
  138.       Constant:    1     2     3     4     5     6     7     8
  139.       Accelerating:1 2  3    4     5      6       7          8
  140.       Decelerating:1          2       3      4     5    6  7 8
  141.       A & D:       1  2    3       4         5       6    7  8
  142.  
  143.    The tweening process as described has one serious limitation and
  144.    that is that most motion is not linear over anything but very short
  145.    durations meaning that a large number of key frames must be
  146.    created.  This means that a complex objects has to be redrawn with
  147.    subtle differences in a large number of key frames by the animator.
  148.  
  149.    One solution to this is to have a simple model, such as a stick
  150.    figure, represent the object for all intermediate key frames.  Once
  151.    they are correctly positioned for animation the detailed object can
  152.    be drawn around the stick figure.  This is the basis for skeletal
  153.    animation.
  154.  
  155.    Consider a skeleton as a backbone and an outline which highlights
  156.    the extent of the area bound to each segment of the backbone.
  157.    Using the outline the object can be transformed into relative
  158.    coordinates.  Then as the backbone or outline is moved the object
  159.    can be recreated to reflect that motion by simply inverse
  160.    transforming the relative coordinates with the new outline.
  161.  
  162.    This technique does have the disadvantage of requiring more input
  163.    than the linear interpolation tweening previously described but its
  164.    implementation can be made such that the two can be used
  165.    individually or in concert. This way the animator can choose the
  166.    combination which yields the best results from the most minimum
  167.    effort.
  168.    
  169.